package com.kzd.gtgame.main.access

import androidx.core.widget.addTextChangedListener
import com.kzd.gtgame.R
import com.kzd.gtgame.custom.setOnClickAntiShakeListener
import com.kzd.gtgame.jetpack.vm.AccessViewModel
import com.module.lemlin.owner.OwnerViewModeFragment
import kotlinx.android.synthetic.main.fragment_access_pwd_setting.*

class AccessPwdSettingFragment : OwnerViewModeFragment<AccessViewModel>() {

    companion object {
        fun newInstance(): AccessPwdSettingFragment {
            return AccessPwdSettingFragment()
        }
    }

    override fun viewModel(): AccessViewModel {
        return createViewModel(requireActivity())
    }

    override val layoutResId: Int
        get() = R.layout.fragment_access_pwd_setting

    override fun initView() {

        etAccessPwdSettingNew.addTextChangedListener {
            tvAccessPwdSettingSubmit.isEnabled = !it.isNullOrEmpty() &&
                    !etAccessPwdSettingNewSure.text.isNullOrEmpty()
        }
        etAccessPwdSettingNewSure.addTextChangedListener {
            tvAccessPwdSettingSubmit.isEnabled = !it.isNullOrEmpty() &&
                    !etAccessPwdSettingNew.text.isNullOrEmpty()
        }
        tvAccessPwdSettingSubmit.setOnClickAntiShakeListener {
            viewModel.accessSettingPwd(
                etAccessPwdSettingNew.text.toString(),
                etAccessPwdSettingNewSure.text.toString()
            )
        }
    }

    override fun initViewMode() {

    }

}